﻿Public Class Rubigeo

    Public Shared Function Seleccionar(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean) As List(Of Eubigeo)
        Dim departamentos As List(Of Eubigeo) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                departamentos = Dubigeo.Seleccionar(descEmpresa)
                If departamentos Is Nothing Then departamentos = New List(Of Eubigeo)
                If DisplaySelect Then departamentos.Insert(0, New Eubigeo("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return departamentos
    End Function
    Public Shared Function SeleccionarTodoXDepartamento(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean) As List(Of Eubigeo)
        Dim departamentos As List(Of Eubigeo) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                departamentos = Dubigeo.SeleccionarTodoXDepartamento(descEmpresa)
                If departamentos Is Nothing Then departamentos = New List(Of Eubigeo)
                If DisplaySelect Then departamentos.Insert(0, New Eubigeo("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return departamentos
    End Function
    Public Shared Function SeleccionarTodoXProvincia(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal idDepartamento As String) As List(Of Eubigeo)
        Dim provincias As List(Of Eubigeo) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                provincias = Dubigeo.SeleccionarTodoXProvincia(descEmpresa, idDepartamento)
                If provincias Is Nothing Then provincias = New List(Of Eubigeo)
                If DisplaySelect Then provincias.Insert(0, New Eubigeo("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return provincias
    End Function
    Public Shared Function SeleccionarTodoXDistrito(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal idDepartamento As String, ByVal idProvincia As String) As List(Of Eubigeo)
        Dim distritos As List(Of Eubigeo) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                distritos = Dubigeo.SeleccionarTodoXDistrito(descEmpresa, idDepartamento, idProvincia)
                If distritos Is Nothing Then distritos = New List(Of Eubigeo)
                If DisplaySelect Then distritos.Insert(0, New Eubigeo("00", "-- SELECCIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return distritos
    End Function

    '******* RptGerenciales xDistrito  *******'
    Public Shared Function rptGerenciales_xDistrito(ByVal descEmpresa As String, ByVal DisplaySelect As Boolean, ByVal rptGerencial As EproformaCabecera) As List(Of Eubigeo)
        Dim ubigeos As List(Of Eubigeo) = Nothing

        Dim options As New TransactionOptions
        options.IsolationLevel = Transactions.IsolationLevel.ReadCommitted
        options.Timeout = New TimeSpan(0, 2, 0)

        Using scope As New TransactionScope(TransactionScopeOption.Required, options)
            Try
                ubigeos = Dubigeo.rptGerenciales_xDistrito(descEmpresa, rptGerencial)
                If ubigeos Is Nothing Then ubigeos = New List(Of Eubigeo)
                'If DisplaySelect Then accions.Insert(0, New xOperaciones("00", "-- SELECIONAR --"))
                scope.Complete()
            Catch ex As Exception
                Throw
            End Try
        End Using

        Return ubigeos
    End Function

    'Private Shared ubigeo As New Eubigeo
    'Public Shared Function XDepartamento(ByVal ubigeos As List(Of Eubigeo)) As List(Of Eubigeo)
    '    Return ubigeos.FindAll(AddressOf CondicionDepartamento)
    'End Function
    'Private Shared Function CondicionDepartamento(ByVal u As Eubigeo) As Boolean
    '    Return u.idUbigeo = ubigeo.idUbigeo.Substring(1, 2).PadRight(6, "0")
    'End Function
    'Public Shared Function XProvincia(ByVal ubigeos As List(Of Eubigeo), ByVal idUbigeo As String) As List(Of Eubigeo)
    '    ubigeo.idUbigeo = idUbigeo
    '    Return ubigeos.FindAll(AddressOf CondicionProvincia)
    'End Function
    'Private Shared Function CondicionProvincia(ByVal u As Eubigeo) As Boolean
    '    Return u.idUbigeo Like ubigeo.idUbigeo.Substring(1, 2).PadRight(6, "0") AndAlso _
    '           ubigeo.idUbigeo.Substring(3, 4) <> "0000"
    'End Function
    'Public Shared Function XDistrito(ByVal ubigeos As List(Of Eubigeo), ByVal idUbigeo As String) As List(Of Eubigeo)
    '    ubigeo.idUbigeo = idUbigeo
    '    Return ubigeos.FindAll(AddressOf CondicionDistrito)
    'End Function
    'Private Shared Function CondicionDistrito(ByVal u As Eubigeo) As Boolean
    '    Return u.idUbigeo Like ubigeo.idUbigeo.Substring(1, 2).PadRight(6, "0") AndAlso _
    '           ubigeo.idUbigeo.Substring(5, 2) <> "00"
    'End Function

End Class
